package cn.farm.farm.Aop;


import cn.farm.farm.Util.redis.JedisAdapter;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class TestIncrHotProtected {


    @Autowired
    JedisAdapter jedisAdapter;

    @Value("${Jedis.protectKey}")
    String hotMessageKey;

    @Pointcut("@annotation(cn.farm.farm.Aop.IncrHotProtected)")
    public void incrHotProtected(){}

    @Before("incrHotProtected()")
    public void before(JoinPoint joinPoint){
        Object[] objects = joinPoint.getArgs();
        int protectedID = (int) objects[0];
        jedisAdapter.zincrby(hotMessageKey,1 ,protectedID+"");
    }
}
